package com.unittec.drainage.provider.utils;

import org.springframework.beans.BeanUtils;

import com.unittec.drainage.sdk.root.internal.exception.BusinessException;

/**
 * @Description:
 * @Author: wuxinwei
 * @CreateDate: 2019/11/20 16:26
 */
public class CopyUtils {

    public static void copyProperties(Object source, Object target) {
        if (source == null || target == null) {
            throw new BusinessException("对象复制异常");
        }
        BeanUtils.copyProperties(source, target);
    }

    /**
     * @param source
     * @param targetClass
     */
    public static <E, T> T copyProperties(E source, Class<T> targetClass) {
        if (null == targetClass) {
            throw new BusinessException("对象复制异常");
        }
        T target = BeanUtils.instantiateClass(targetClass);
        if (source == null) {
            return target;
        }
        BeanUtils.copyProperties(source, target);
        return target;
    }
}
